/**
 * Created by koudaiwang on 2017/6/16.
 */


var News = require('./dao').News;
module.exports = {
    create: function create(news) {
        return News.create(news).exec();
    },

    getAllNews: function getAllNews() {
        return News.find().sort({ _id: -1}).addCreatedAt().exec();
    },

    getNewsByAuthor: function (author) {
        var query = {};
        if (author) {
            query.author = author;
        }
        return News.find(query).sort({ _id: -1}).exec();
    },

    delNewsByAuthor: function (author) {
        var query = {};
        if (author) {
            query.author = author;
        }
        return News.remove(query).exec();
    },

    getNewsByType: function (type) {
        var query = {};
        if (type) {
            query.type = type;
        }
        return News.find(query).sort({ _id: -1}).exec();
    },

    getNewsByID: function(ID) {
        var query = {};
        if (ID) {
            query._id = ID;
        }
        return News.find(query).sort({ _id: -1}).exec();
    },
    
    updateNews: function (content) {
        
    }
};